import {
	observable,
	action,
	computed,
} from 'mobx';
import {
	Tools,
} from "weaver-mobile";
import * as api from '../../apis/passwordSetting';
const getLabel = Tools.getLabel;

class PasswordSetting {
	@observable isOpenSecondaryPwd = false;
	@observable showSecuritySetting = false

	@observable selectedKey = '0';

	@computed get tabs() {
		const datas = [{
			title: getLabel(388431, '登录密码'),
			key: '0'
		}];
		if (this.isOpenSecondaryPwd) {
			datas.push({
				title: getLabel(501204, '二次验证密码'),
				key: '1'
			})
		};
		if (this.showSecuritySetting) {
			datas.push({
				title:getLabel('81604', "密保设置"),
				key: '2'
			})
		}

		return datas;
	}

	get tabProps() {
		return {
			onTabClick: (data) => {
				this.selectedKey = data.key;
			}
		}
	}


	@action init = () => {
		api.isOpenSecondaryPwd().then(datas => {
			const {
				isOpenSecondaryPwd,
				securityQuestion,
			} = datas;
			this.isOpenSecondaryPwd = (isOpenSecondaryPwd === '1');
			this.showSecuritySetting = (securityQuestion === '1');
		})
	}

}

export const passwordSetting = new PasswordSetting();